package com.example.bytebuddy;

import net.bytebuddy.ByteBuddy;
import net.bytebuddy.dynamic.DynamicType;
import net.bytebuddy.implementation.FixedValue;
import net.bytebuddy.matcher.ElementMatchers;

/**
 * 
 * https://zhuanlan.zhihu.com/p/151843984
 * 
 * @author simple
 *
 */
public class ByteTestOne {
	public static void main(String[] args) throws Exception {
		DynamicType.Unloaded unloadedType = new ByteBuddy().subclass(Object.class).method(ElementMatchers.isToString())
				.intercept(FixedValue.value("Hello World ByteBuddy!")).make();
		
//		unloadedType.toJar(new File("./data/x.jar"));
		
		Class<?> dynamicType = unloadedType.load(ByteBuddy.class.getClassLoader()).getLoaded();
		
		
		System.err.println(dynamicType.newInstance().toString());
		
		
	}
}
